//
//  ViewController.m
//  自定义布局
//
//  Created by 耐克了解了 on 17/4/17.
//  Copyright © 2017年 耐克了解了. All rights reserved.
//

#import "ViewController.h"
#import "LineLayout.h"
#import "TWPhotoCell.h"


static NSString *cellID = @"cell";

@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    LineLayout *layout = [[LineLayout  alloc]init];
    layout.itemSize = CGSizeMake(120, 150);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    CGFloat width = self.view.frame.size.width;
    CGRect frame = CGRectMake(0, 100, width, 250);
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:frame collectionViewLayout:layout];
    [self.view addSubview:collectionView];
   // [collectionView registerClass:[TWPhotoCell class] forCellWithReuseIdentifier:cellID];
    
    [collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([TWPhotoCell class]) bundle:nil] forCellWithReuseIdentifier:cellID];
    collectionView.dataSource = self;
    collectionView.delegate = self;
   // collectionView.pagingEnabled = YES;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 20;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TWPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
 
    cell.imageName = [NSString stringWithFormat:@"%zd",indexPath.item +1];
    
//    NSInteger tag = 10;
//    
//    UILabel *label = [cell.contentView viewWithTag:tag];
//    if (label == nil) {
//        label = [[UILabel alloc]init];
//        label.tag = 10;
//        [cell.contentView addSubview:label];
//    }
//    label.text = [NSString stringWithFormat:@"%zd",indexPath.item];
    
  //  [label sizeToFit];
  return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
